package service

import (
	"file_sys_server/model"
	"file_sys_server/serializer"
)

type Channel4RegionService struct {
	Left1     uint   `json:"left1"`
	Right1    uint   `json:"right1"`
	Top1      uint   `json:"top1"`
	Bottom1   uint   `json:"bottom1"`
	BgFactors string `json:"bgFactors"`

	Left2      uint   `json:"left2"`
	Right2     uint   `json:"right2"`
	Top2       uint   `json:"top2"`
	Bottom2    uint   `json:"bottom2"`
	BgFactors2 string `json:"bgFactors2"`

	Left3      uint   `json:"left3"`
	Right3     uint   `json:"right3"`
	Top3       uint   `json:"top3"`
	Bottom3    uint   `json:"bottom3"`
	BgFactors3 string `json:"bgFactors3"`

	Left4      uint   `json:"left4"`
	Right4     uint   `json:"right4"`
	Top4       uint   `json:"top4"`
	Bottom4    uint   `json:"bottom4"`
	BgFactors4 string `json:"bgFactors4"`
}

//通道4 校准数据的增删改查

func (service *Channel4RegionService) AddRecord() serializer.Response {
	record := model.ChannelRegion_4UnionBean{
		// ID:        1,
		Left1:     service.Left1,
		Right1:    service.Right1,
		Top1:      service.Top1,
		Bottom1:   service.Bottom1,
		BgFactors: service.BgFactors,

		Left2:      service.Left2,
		Right2:     service.Right2,
		Top2:       service.Top2,
		Bottom2:    service.Bottom2,
		BgFactors2: service.BgFactors2,

		Left3:      service.Left3,
		Right3:     service.Right3,
		Top3:       service.Top3,
		Bottom3:    service.Bottom3,
		BgFactors3: service.BgFactors3,

		Left4:      service.Left4,
		Right4:     service.Right4,
		Top4:       service.Top4,
		Bottom4:    service.Bottom4,
		BgFactors4: service.BgFactors4,
	}

	err := model.DB.Create(&record).Error

	if err != nil {
		return serializer.Response{
			Code: 10003,
			Msg:  err.Error(),
		}
	}

	return serializer.Response{
		Code: 10000,
		Msg:  "success",
	}
}

// 获取校准数据
func GetChannel4Record() (*model.ChannelRegion_4UnionBean, error) {
	var calibration *model.ChannelRegion_4UnionBean
	err := model.DB.Last(&calibration).Error

	return calibration, err
}
